﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;

namespace NetCoreQrCoreDemo.Common
{
    public class InfoHub : Hub
    {
        //public static IHubContext<InfoHub> GlobalHub { get; private set; }
        private readonly GlobalHubServer<InfoHub> _hubMethods;

        public InfoHub(GlobalHubServer<InfoHub> ctx)
        {
            //GlobalHub = ctx;
            _hubMethods = ctx;
        }
        public override Task OnConnectedAsync()
        {
            var id = Context.ConnectionId;
            ReceiveMessage(id);
            return base.OnConnectedAsync();
        }

        public Task ReceiveMessage(string cid)
        {
            return Clients.Client(cid).SendAsync("GetClientId", new { Cid = cid, NewCode = Guid.NewGuid() });
        }

        public Task RequestNewCode(string cid)
        {
            return Clients.Client(cid).SendAsync("GetClientId", new { Cid = cid, NewCode = Guid.NewGuid() });
        }
    }
}
